// __PUBLIC__/js/page/admin/global/editdocument
require(['../../common'], function() {
  require(['global.editdocument'])
})

define('global.editdocument', [
    'jquery'
  ], function($) {
    'use strict';
  function editDocument(id) {
    var type = "{$type}";
    var title = document.getElementById("title").value;
    var content = document.getElementById("content_1").value;
    var is_active = "";
    if (document.getElementById("is_active_1").checked)
      is_active = "1";
    if (document.getElementById("is_active_0").checked)
      is_active = "0";
    var is_on_footer = "";
    if (document.getElementById("is_on_footer_1").checked)
      is_on_footer = "1";
    if (document.getElementById("is_on_footer_0").checked)
      is_on_footer = "0";

    if (title == '') {
      $("#vaname").html('*'+lang.notNull).css('color', 'red');//不能为空
      return;
    }

    $.post("{:URL('admin/Global/doEditDocument')}", {
      type : type,
      title : title,
      is_active : is_active,
      is_on_footer : is_on_footer,
      content : content,
      document_id : id
    }, function(res) {
      var len = res.length
      for (i = 0; i < len; i++) {
        res = res.replace("\n", "");
      }
      //alert(res);
      if (res == "1") {
        $("#vaname").html('*'+lang.titleHaving).css('color',
            'red');//标题已经存在
      } else if (res == "2") {
        alert(lang.saveSuccess);//保存成功
        //setInterval(function() {
        window.location.href = "{:URL('admin/Global/document')}";
        //},30);
      } else if (res == "0") {
        $("#vaname").html(lang.saveFails)
            .css('color', 'red');//保存失败
      }
    });
  }
  function cancel() {
    window.location.href = "{:URL('admin/Global/document')}";
  }

  })
